import { sexStatus } from '@/views/signUp/components/status';
import {
  voiceAnchorOptions,
  frameOutOptions,
  recommendRankOptions,
  mutualselectOptions,
  mutualselectFilter,
  voiceAnchorFilter,
  frameOutFilter,
  recommendRankFilter,
  privateDeductionTaxRateOptions
} from '@/utils/const/resouce';

export function getPlatformTypeName(id, arr = []) {
  let name = '';
  arr.forEach(el => {
    if (el.id === id) {
      name = el.value;
    }
  });
  return name;
}
export function getOperateModeName(val, arr = []) {
  let name = '';
  arr.forEach(el => {
    if (el.value === val) { name = el.label; }
    if (el.children && el.children.length) {
      el.children.forEach(j => {
        if (j.value === val) { name = j.label; }
      });
    }
  });
  return name;
}
export function isNodeIdExistInTree(nodeId, tree, childrenKey = 'children') {
  if (!tree || !Array.isArray(tree)) {
    return false;
  }
  for (const node of tree) {
    if (node.id === nodeId) {
      return true;
    }
    if (node[childrenKey] && Array.isArray(node[childrenKey])) {
      const isExistInChildren = isNodeIdExistInTree(nodeId, node[childrenKey]);
      if (isExistInChildren) {
        return true;
      }
    }
  }
  return false;
}
// 计算月份
export function getMonth(start, end) {
  const startYear = new Date(start).getFullYear();
  const endYear = new Date(end).getFullYear();
  const startMonth = new Date(start).getMonth() + 1;
  const endMonth = new Date(end).getMonth() + 1;
  return (endYear - startYear) * 12 + (endMonth - startMonth) + 1;
}
// 需要上刊的平台
const journalPlatforms = ['小红书', '抖音', '微博', 'B站', '快手', '微信', '微信视频号'];
export function isJournalPlatform(platformName) {
  return journalPlatforms.includes(platformName);
}
// platformCategory，1:微信 2: 微博 3:小红书 4.抖音 5:更多  6:直播 7:B站
export const accountAllField = [
  { label: '粉丝量', keyword: 'fansNum', parentKey: 'moreAccountInfo', type: 'number', required: true, trigger: 'blur' },
  { label: '平均阅读量', keyword: 'averageReadNum', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [1, 2, 3] },
  { label: '曝光量', keyword: 'exposure', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [3] },
  { label: '平均播放量', keyword: 'averagePlayNum', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [4, 5, 7] },
  { label: '平均互动总和', keyword: 'averageInteractionNum', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [2, 3, 4] },
  { label: '平均点赞量', keyword: 'averageLikeNum', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [5, 6, 7] },
  { label: '性别', keyword: 'sex', parentKey: 'additionalKey', type: 'select', options: [{ id: 0, value: '男' }, { id: 1, value: '女' }], filterFn: sexStatus, clearable: true, requiredPlatform: ['小红书', '抖音', '微博', 'B站', '快手'], trigger: 'change' },
  { label: '达人所在城市', keyword: 'city', parentKey: 'additionalKey', type: 'area', requiredPlatform: ['小红书', '抖音', '微博', 'B站'], trigger: 'change', labelCollapse: true, noDetailCollapse: true },
  { label: '赞与收藏', keyword: 'collection', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [2, 3, 4, 7], required: true, trigger: 'change' },
  { label: '简介', keyword: 'summary', parentKey: 'additionalKey', type: 'input', platformCategory: [1, 2, 3, 4, 7], required: true, trigger: 'blur', maxlength: 200, clearable: true },
  { label: '微信号', keyword: 'wxCode', parentKey: 'moreAccountInfo', type: 'input', platformCategory: [1], required: true, trigger: 'blur', maxlength: 200, clearable: true },
  { label: '受众群体', keyword: 'audience', parentKey: 'moreAccountInfo', type: 'input', platformCategory: [1], required: true, trigger: 'blur', maxlength: 200, clearable: true },
  { label: '日常文章头条平均阅读量', keyword: 'dailyAverageReadNum', parentKey: 'moreAccountInfo', type: 'number', platformCategory: [1], required: true, trigger: 'blur', clearable: true, labelCollapse: true },
  { label: '微信生态内影响力', keyword: 'wxInfluence', parentKey: 'moreAccountInfo', type: 'input', platform: ['微信视频号'], required: true, trigger: 'blur', maxlength: 200, clearable: true, labelCollapse: true },
  { label: '外站影响力', keyword: 'outInfluence', parentKey: 'moreAccountInfo', type: 'input', platform: ['微信视频号'], required: true, trigger: 'blur', maxlength: 200, clearable: true }
];
export const moreJournalFields = [
  { label: '推荐优先级', keyword: 'recommendRank', parentKey: 'additionalKey', type: 'select', platformCategory: [2, 3, 4, 7], options: recommendRankOptions, filterFn: recommendRankFilter, clearable: true },
  { label: '私单扣费税点数', keyword: 'privateDeductionTaxRate', parentKey: 'additionalKey', type: 'select', platformCategory: [4], options: privateDeductionTaxRateOptions, required: true, labelCollapse: true, clearable: true },
  { label: '是否露脸', keyword: 'isFrameOut', parentKey: 'additionalKey', type: 'select', required: true, trigger: 'change', platformCategory: [1, 3], platform: ['快手', '微信视频号'], options: frameOutOptions, filterFn: frameOutFilter, clearable: true },
  { label: '是否口播', keyword: 'isVoiceAnchor', parentKey: 'additionalKey', type: 'select', required: true, trigger: 'change', platformCategory: [1, 3], platform: ['快手', '微信视频号'], options: voiceAnchorOptions, filterFn: voiceAnchorFilter, clearable: true },
  { label: '达人配合度/性格', keyword: 'masterFit', parentKey: 'additionalKey', type: 'input', required: true, trigger: 'blur', platformCategory: [1, 3], platform: ['快手', '微信视频号'], labelCollapse: true },
  { label: '接单诉求', keyword: 'orderRequest', parentKey: 'additionalKey', type: 'input', required: true, trigger: 'blur', platformCategory: [1, 3], platform: ['快手', '微信视频号'] },
  { label: '是否开通互选', keyword: 'mutualselect', parentKey: 'additionalKey', type: 'radio', required: true, trigger: 'blur', options: mutualselectOptions, filterFn: mutualselectFilter, platformCategory: [1], labelCollapse: true, noDetailCollapse: true },
  { label: '广告案例', keyword: 'adExample', parentKey: 'additionalKey', type: 'input', required: true, trigger: 'blur', platformCategory: [1] },
  { label: '原创视频需求', keyword: 'originVideoRequst', parentKey: 'additionalKey', type: 'input', required: true, trigger: 'blur', platform: ['微信视频号'], labelCollapse: true, noDetailCollapse: true },
  { label: '合作品牌&获奖经历', keyword: 'brandExperience', parentKey: 'additionalKey', type: 'input', required: true, trigger: 'blur', platform: ['微信视频号'], labelCollapse: true },
  {
    keyword: 'freeAuth',
    children: [
      { label: '可全平台免费授权6个月信息流/电商投放以及二次剪辑', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [1, 2, 3, 4, 7], platform: ['快手', '微信视频号'] },
  {
    keyword: 'otherFreePlatform',
    children: [
      { label: '可免费同步其他平台', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [1, 2, 3, 4, 7], platform: ['快手', '微信视频号'] },
  {
    keyword: 'hasShopPrice',
    children: [
      { label: '可免费同城探店', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [1, 2, 3, 4, 7], platform: ['快手', '微信视频号']
  },
  {
    keyword: 'retentionAllowed',
    children: [
      { label: '可永久保留内容', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change', linkKey: 'timeLimit' },
      { label: '备注', keyword: 'timeLimit', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [1, 3], platform: ['快手', '微信视频号']
  },
  {
    keyword: 'addBrand',
    children: [
      { label: '可免费添加品牌标记组件，评论区组件等', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [1, 3], platform: ['快手', '微信视频号']
  },
  {
    keyword: 'allowCar',
    children: [
      { label: '可免费挂车', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', maxlength: 200, required: true, trigger: 'blur' }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [4]
  },
  {
    keyword: 'carCommission',
    children: [
      { label: '对挂车佣金无要求', keyword: 'isConfirm', type: 'switch', required: true, trigger: 'change' },
      { label: '备注', keyword: 'cost', type: 'input', required: true, trigger: 'blur', maxlength: 200 }
    ],
    parentKey: 'additionalKey', type: 'confirm', platformCategory: [4]
  }
];
const journalField = {
  '抖音': [
    { name: '星图报价1-20s', keyword: 'starMapTwenty', required: true, labelCollapse: true },
    { name: '星图报价20-60s', keyword: 'starMapSixty', required: true, labelCollapse: true },
    { name: '星图报价60s以上', keyword: 'starMapAboveSixty', required: true, labelCollapse: true },
    { name: '内容合集单坑位报价', keyword: 'contentCollectionPrice', type: 'string', labelCollapse: true }
  ],
  '微博': [
    { name: '非原创直发', keyword: 'publish', required: true },
    { name: '非原创转发', keyword: 'forward', required: true },
    { name: '原创图文', keyword: 'originalContent', required: true, labelCollapse: true },
    { name: '原创视频', keyword: 'originalVideo', required: true, labelCollapse: true }
  ],
  'B站': [
    { name: '定制视频', keyword: 'customVideo', required: true },
    { name: '植入视频', keyword: 'implantationVideo', required: true },
    { name: '直发动态', keyword: 'publishTrends', required: true },
    { name: '转发动态', keyword: 'forwardTrends', required: true }
  ],
  '微信': [
    { name: '头条供稿发布价', keyword: 'topFeedPrice', required: true, labelCollapse: true },
    { name: '头条原创发布价', keyword: 'topOriginPrice', required: true, labelCollapse: true },
    { name: '次条供稿发布价', keyword: 'nextTopFeedPrice', required: true, labelCollapse: true },
    { name: '次条原创发布价', keyword: 'nextTopOriginPrice', required: true, labelCollapse: true }
  ],
  '微信视频号': [
    { name: '直发视频报价（不含链接）', keyword: 'publishVideoNoLinkPrice', required: true, labelCollapse: true },
    { name: '直发视频报价（含链接）', keyword: 'publishVideoLinkPrice', required: true, labelCollapse: true },
    { name: '直发链接报价（视频为博主日常内容）', keyword: 'publishLinkPrice', required: true, labelCollapse: true }
  ]
};

export function getJournalFields(platformName) {
  if (!platformName) return [];
  return journalField[platformName] || [];
}
